package com.modernyuanshiren.sample;

import com.modernyuanshiren.IElement;
import com.modernyuanshiren.ISingleAction;

public enum SampleSingleAction implements
		ISingleAction<SampleStatus, SampleSingleAction> {
	MOVE_LEFT("左移1格") {
		@Override
		public void apply(SampleStatus status, IElement... elements) {
			this.translate(elements[0], -1);
			this.translate(elements[1], 1);
		}

		@Override
		public boolean acceptable(	SampleStatus status,IElement... elements) {
			if (elements.length != 2) {
				return false;
			}
			if (!elements[1].is(Game.getGameContext().getEmptyName())) {
				return false;
			}
			IElement element = elements[0];
			return element.is(Game.getGameContext().getRightName())
					&& status.is(status.leftOf(element), elements[1]);
		}
	},
	JUMP_LEFT("左跳") {
		@Override
		public void apply(SampleStatus status, IElement... elements) {
			this.translate(elements[0], -2);
			this.translate(elements[1], 2);
		}

		@Override
		public boolean acceptable(	SampleStatus status,IElement... elements) {
			if (elements.length != 2) {
				return false;
			}
			if (!elements[1].is(Game.getGameContext().getEmptyName())) {
				return false;
			}
			IElement element = elements[0];
			return element.is(Game.getGameContext().getRightName())
					&& element.getPosition().getX() == elements[1].getPosition().getX() + 2
					&& status.is(status.leftOf(element), Game.getGameContext()
							.getLeftName());
		}
	},
	MOVE_RIGHT("右移1格") {
		@Override
		public void apply(SampleStatus status, IElement... elements) {
			this.translate(elements[0], 1);
			this.translate(elements[1], -1);
		}

		@Override
		public boolean acceptable(	SampleStatus status,IElement... elements) {
			if (elements.length != 2) {
				return false;
			}
			if (!elements[1].is(Game.getGameContext().getEmptyName())) {
				return false;
			}
			IElement element = elements[0];
			return element.is(Game.getGameContext().getLeftName())
					&& status.is(status.rightOf(element), elements[1]);
		}
	},
	JUMP_RIGHT("右跳") {
		@Override
		public void apply(SampleStatus status, IElement... elements) {
			this.translate(elements[0], 2);
			this.translate(elements[1], -2);
		}

		@Override
		public boolean acceptable(	SampleStatus status,IElement... elements) {
			if (elements.length != 2) {
				return false;
			}
			if (!elements[1].is(Game.getGameContext().getEmptyName())) {
				return false;
			}
			IElement element = elements[0];
			return element.is(Game.getGameContext().getLeftName())
					&& element.getPosition().getX() == elements[1].getPosition().getX() - 2
					&& status.is(status.rightOf(element), Game.getGameContext()
							.getRightName());
		}
	},

	;

	@Override
	public boolean notNecessary(SampleSingleAction preAction) {
		return false;
	}

	private String name;

	private SampleSingleAction(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		return name;
	}
}
